package com.yunxin.core.utils.infra.utils;

import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.TextStyle;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * @author zero°
 * @since 2023-06-05
 */
@Slf4j
public enum DateUtils {

    /**
     * 单例
     */
    X;


    private  Long getAroundMinute(Date date, int minute) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MINUTE, minute);
        return calendar.getTime().getTime();
    }

    public Long getAroundMinute(int minute) {
        return getAroundMinute(new Date(), minute);
    }


    /**
     * 判断时间是否在时间段内
     * @param nowTime nowTime
     * @param beginTime beginTime
     * @param endTime endTime
     * @return Boolean
     */
    public Boolean belongCalendar(Date nowTime, Date beginTime, Date endTime) {
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);

        Calendar begin = Calendar.getInstance();
        begin.setTime(beginTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        return date.compareTo(begin) >= 0 && date.compareTo(end) <= 0;
    }

    /**
     * 判断当前时间是否在时间段内 HH:mm
     * @param localDateTime 当前时间
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return Boolean
     */
    public Boolean belongLocalTime(LocalDateTime localDateTime, String startTime, String endTime) {
        LocalTime currentLocalTime = localDateTime.toLocalTime();
        LocalTime startLocalTime = LocalTime.parse(startTime);
        LocalTime endLocalTime = LocalTime.parse(endTime);
        return currentLocalTime.isAfter(startLocalTime)&&endLocalTime.isAfter(currentLocalTime);
    }

    /**
     * 获得今天星期几
     * @return String
     */
    public String getTodayWeek(LocalDateTime localDateTime){
        LocalDate localDate = localDateTime.toLocalDate();
        return localDate.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.CHINESE);
    }

}

